package com.sc.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.sc.bean.T_library;
import com.sc.bean.T_waiting;
import com.sc.bean.User;
import com.sc.serviceimpl.ApproverImpl;
import com.sc.serviceimpl.LibraryServiceImpl;
import com.sc.serviceimpl.WaitingServiceImpl;


@Controller
public class LibraryController {

	@Autowired
	private WaitingServiceImpl waiServiceImpl;
	
	@Autowired
	private ApproverImpl approverImpl;
	
	@Autowired
	private LibraryServiceImpl libraryServiceImpl;
	
	@RequestMapping("addlibrary")
	public String addlibrary(HttpServletRequest  request,Model model){
		String fan="";
		T_library library=new T_library();
		library.setLi_approver(request.getParameter("approver"));
		library.setLi_day(request.getParameter("day"));
		library.setLi_dept(request.getParameter("dept"));	
		library.setLi_no(request.getParameter("lno"));
		library.setLi_lname(request.getParameter("lname"));
		library.setLi_uname(request.getParameter("uname"));
		library.setLi_img(request.getParameter("img"));
		System.out.println(request.getParameter("lname"));
		System.out.println(request.getParameter("img"));
		int i = libraryServiceImpl.add(library);
		
		List<User> userList=approverImpl.find();
		
		model.addAttribute("userList",userList);
		model.addAttribute("str", 222);
		String result="";
		
		if(i!=1){
			result="申请失败";
			fan="addLibrary";
			System.out.println( "申请失败");
		}else{						
			System.out.println( "申请成功");
			T_waiting wai=new T_waiting();
			wai.setWt_pname(request.getParameter("uname"));
			wai.setWt_tname(request.getParameter("uname")+"图书申请");
			wai.setWt_status("未审核");
			wai.setWt_starttime(request.getParameter("day"));
			wai.setWt_table("t_library");
			int a = waiServiceImpl.add(wai);

			if(a!=1){	
				System.out.println("添加审核失败");
			}else{
				fan="waiting";
				System.out.println("添加审核成功");
			}
		}
		model.addAttribute("result",result);
		return fan;
	}

	
	
	
	
}
